﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace System.Web.UI
{
    public class ZWMPage : ZWPage
    {
        protected override void CheckRights()
        {
            base.CheckRights();
            string cookieUID = GetValueFromCookie(this.Context, "ZESessionMemberUID");
            if (cookieUID!="")
            {
                ZSession.MemberUID = cookieUID;
            }
            if (ZSession.MemberUID == "" || ZSession.MemberUID == null)
            {
                Thread.Sleep(ZSetup.SleepTimes);
                Response.Redirect(ZPath.RootVirtualURI+"Member/Login.aspx?URL=" + Request.Url);
            }
        }

        protected override void SetOutCache()
        {
            
        }
        public static void SetSessionToCookie(Page page, string name, string value, string domain)
        {
            HttpCookie cookie = new HttpCookie(name, HttpUtility.UrlEncode(value));
            cookie.Domain = domain;
            page.Response.Cookies.Add(cookie);
        }

        public static string GetValueFromCookie(HttpContext context, string name)
        {
            if (context.Request.Cookies[name] != null)
            {
                return HttpUtility.UrlDecode(context.Request.Cookies[name].Value);
            }
            return "";
        }
    }
}
